package com.twu.biblioteca.library;

import com.twu.biblioteca.items.Book;
import com.twu.biblioteca.items.Movie;
import com.twu.biblioteca.users.UserAccountsManager;

import java.util.HashMap;

/**
 * @author Alvi Jonathan Sait
 */
public class Library implements ILibraryItemCollector {

    private final HashMap<String, Book> books;
    private final HashMap<String, Movie> movies;
    private final UserAccountsManager userAccountsManager;

    public Library() {
        this.books = new HashMap<String, Book>();
        this.movies = new HashMap<String, Movie>();
        this.userAccountsManager = new UserAccountsManager();
    }

    @Override
    public void checkoutBook(Book book) {
        this.books.put(book.getISBN(), book);
    }

    /**
     * A library can't return a book to anyone since the library should be the recipient of the book.
     * Will throw UnsupportedOperationException when called.
     *
     * @param book
     * @throws UnsupportedOperationException
     */
    @Override
    public void returnBook(Book book) {
        throw new UnsupportedOperationException("The library can't return any book.");
    }

    /**
     * Only returns a copy of the map.
     */
    @Override
    public HashMap<String, Book> getBooks() {
        return new HashMap<String, Book>(books);
    }

    @Override
    public void checkoutMovie(Movie movie) {
        movies.put(movie.getMovieId(), movie);
    }

    /**
     * Only returns a copy of the map.
     */
    @Override
    public HashMap<String, Movie> getMovies() {
        return new HashMap<String, Movie>(movies);
    }

    public UserAccountsManager getUserAccountsManager() {
        return userAccountsManager;
    }
}
